export function getToken () {
  let u = navigator.userAgent
  let token = u.substr(u.indexOf('AppToken') + 9)
  return token
}

export function getClientType () {
  let u = navigator.userAgent

  if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {
    return 'android'
  }
  if (u.indexOf('iphone')) {
    return 'iphone'
  }
  if (u.indexOf('Windows Phone')) {
    return 'WINDOWS iphone'
  }
  return null
}

export function callOcFun (funName, params) {
  let clientType = getClientType()

  if (clientType === 'android') {
    window.control.xiangchangshuFun(JSON.stringify({method: funName, params: params}))
  }

  if (clientType === 'iphone') {
    window.webkit.messageHandlers.xiangchangshuFun.postMessage({
      method: funName,
      params: params
    })
  }
}

export function decodeUnicode (str) {
  // str = str.replace(/\\/g, '%')
  // return unescape(str)
  return str
}

export function toUnicode (str) {
  // return escape(str).toLocaleLowerCase().replace(/%u/gi, '\\u')
  return str
}
